package cn.itcast.tools.java字符串操作;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class java词频统计 {

    static void wordCount() {
        String str = "今天,很好,明天,很好";
        List<String> lines = Arrays.asList(str);
        Map<String, Long> words = lines.stream()
                .flatMap(w -> Stream.of(w.split(",")))
                .collect(Collectors.groupingBy(w -> w, Collectors.counting()));
        System.out.println(words);
    }

    public static void main(String[] args) {
        wordCount();
    }
}
